package com.lkd.emq;

import com.lkd.business.MsgHandler;
import com.lkd.business.MsgHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class MqttServiceImpl implements MqttService {

    @Autowired
    private MsgHandlerContext msgHandlerContext;



    @Override
    public void processMessage(String topic, MqttMessage message) {

        String jsonMsg = new String(message.getPayload());

        MsgHandler msgHandler = msgHandlerContext.getMsgHandler(topic);
        if(msgHandler == null){
            return ;
        }
        msgHandler.process(jsonMsg);
    }
}
